import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Types } from 'mongoose';
import { ApiProperty } from '@nestjs/swagger';

// 评论状态枚举
export enum CommentStatus {
  PENDING = 'pending', // 待审核
  APPROVED = 'approved', // 审核通过
}

@Schema({
  timestamps: {
    createdAt: 'commentTime', // 重命名创建时间为评论时间
    updatedAt: false, // 不需要更新时间
  },
  collection: 'comment', // 集合名称
  versionKey: false, // 不返回版本字段
})
export class Comment extends Document {
  @ApiProperty({ description: '用户头像' })
  @Prop({ required: false, type: String })
  userAvatar: string;

  @ApiProperty({ description: '用户名称' })
  @Prop({ required: true, type: String })
  userName: string;

  @ApiProperty({ description: '评论内容' })
  @Prop({ required: true, type: String })
  content: string;

  @ApiProperty({ description: '评分' })
  @Prop({ required: true, type: Number })
  score: number;

  @ApiProperty({
    description: '评论状态',
    enum: CommentStatus,
    default: CommentStatus.PENDING,
  })
  @Prop({
    required: true,
    type: String,
    enum: CommentStatus,
    default: CommentStatus.PENDING,
  })
  status: CommentStatus;

  @ApiProperty({ description: '评论图片URL数组，最多3张' })
  @Prop({
    type: [String],
  })
  images?: string[];

  @ApiProperty({ description: '关联的商品ID' })
  @Prop({ required: true, type: Types.ObjectId, ref: 'product' })
  productId: Types.ObjectId;
}

export const CommentSchema = SchemaFactory.createForClass(Comment);
